package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;

public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String Code) {
        /*if ("1".equals(Code)){
            return ItemType.APARTMENT;
        }
        if ("2".equals(Code)){
            return ItemType.ROOM;
        }*/
        ItemType[] values = ItemType.values();
        if (values != null){
            for (ItemType itemType : values) {
                if (itemType.getCode().equals(Integer.valueOf(Code))){
                    return itemType;
                }
            }
        }
        throw  new IllegalArgumentException("无效的参数");
    }
}
